package com.gitee.feizns.upload.service;

import com.gitee.feizns.upload.domain.enums.ResourceType;
import com.gitee.feizns.upload.domain.vo.ResourceVo;
import com.gitee.feizns.web.utils.FileUtils;

import java.io.InputStream;
import java.util.UUID;

/**
 * @author feizns
 * @since 2019/8/9
 */
public interface UploadService extends TransactionalConfig {

    /**
     * 上传
     * @param is
     * @param originalFilename
     * @param type
     * @return
     */
    ResourceVo upload(InputStream is, String originalFilename, ResourceType type);

    /**
     * 包装成绝对路径
     * @param filename
     * @return
     */
    String swapAbsoluteUrl(String filename);

    /**
     * 生成唯一文件名
     * @param originalFilename
     * @return
     */
    static String generatorFilename(String originalFilename) {
        String suffix = FileUtils.getSuffix(originalFilename);
        return UUID.randomUUID().toString() + "_" + System.currentTimeMillis() + suffix;
    }

}

